package org.come.Jpanel;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;

import org.come.until.SrcollPanelUI;

import com.tool.btn.FactionBtn;
import com.tool.tcpimg.RichLabel;
import com.tool.tcpimg.UIUtils;

 

/**
 * 帮派战报面板
 * 
 * @author HGC<br>
 * @time 2020年1月11日 上午11:27:54<br>
 * @class 类名:FactionWarJpanel<br>
 */
public class FactionWarJpanel extends JPanel {

    /**
     * 字段名:btnDetails 战报详情<br>
     */
    private FactionBtn btnDetails;

    private JScrollPane scrollPane;

    private JTable table;
    private DefaultTableModel tableModel;

    private RichLabel richLabPandectMsg, richLabLastMsg, richLabMyMsg;

    public FactionWarJpanel() {
        setPreferredSize(new Dimension(662, 475));
        setOpaque(false);
        setLayout(null);

        getScrollPane();
        getBtnDetails();
        getRichLabLastMsg();
        getRichLabMyMsg();
        getRichLabPandectMsg();
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (icon == null) {
            icon = new ImageIcon("inkImg/old/background/S168.png");
        }
        g.drawImage(icon.getImage(), 0, 0, 662, 475, null);
    }

    public FactionBtn getBtnDetails() {
        if (btnDetails == null) {
            btnDetails = new FactionBtn("skin/8100226/newbutton/B22.png", 1, UIUtils.COLOR_BTNPUTONG, "战报详情", UIUtils.TEXT_HY16,
                    15, this);
            btnDetails.setBounds(286, 420, 99, 24);
            this.add(btnDetails);
        }
        return btnDetails;
    }

    public void setBtnDetails(FactionBtn btnDetails) {
        this.btnDetails = btnDetails;
    }

    public JTable getTable() {
        if (table == null) {
            table = new JTable() {
                @Override
                public boolean isCellEditable(int row, int column) {
                    return false;
                }
            };

            // 帮派成员信息表格
            table.setShowGrid(false);
            table.setOpaque(false);

            DefaultTableCellRenderer renderer = new DefaultTableCellRenderer() {

                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                        boolean hasFocus, int row, int column) {
                    // if (row < 3)
                    // setForeground(Color.yellow);
                    // else
                    setForeground(Color.white);

                    return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                }
            };
            renderer.setHorizontalAlignment(SwingConstants.CENTER);
            table.setDefaultRenderer(Object.class, renderer);

            JTableHeader header = table.getTableHeader();

            // 设置表头的高度
            header.setPreferredSize(new Dimension(header.getWidth(), 0));
            table.getTableHeader().setBackground(UIUtils.Color_BACK);
            table.getTableHeader().setVisible(true);
            table.getTableHeader().setBorder(BorderFactory.createLineBorder(Color.ORANGE));

            table.setSelectionBackground(UIUtils.Color_BACK);
            table.setSelectionForeground(Color.white);
            table.setForeground(Color.white);
            table.setFont(UIUtils.TEXT_FONT);
            table.setBackground(UIUtils.Color_BACK);
            table.setModel(getTableModel());

            // 设置列间距590
            table.getColumnModel().getColumn(0).setPreferredWidth(75);
            table.getColumnModel().getColumn(1).setPreferredWidth(90);
            table.getColumnModel().getColumn(2).setPreferredWidth(75);
            table.getColumnModel().getColumn(3).setPreferredWidth(85);
            // 设置行宽
            table.setRowHeight(25);
            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            table.isCellEditable(1, 1);
            table.setEnabled(true);
        }
        return table;
    }

    public void setTable(JTable table) {
        this.table = table;
    }

    public DefaultTableModel getTableModel() {
        if (tableModel == null) {
            tableModel = new DefaultTableModel();
            Vector<Vector<String>> verVectors = new Vector<Vector<String>>();
            for (int i = 0; i < 50; i++) {
                Vector<String> vector = new Vector<>();
                for (int j = 0; j < 4; j++) {
                    vector.add(String.valueOf(j + 1));
                }
                verVectors.add(vector);
            }
            Vector<String> vector3 = new Vector<String>();
            vector3.add("");
            vector3.add("");
            vector3.add("");
            vector3.add("");
            tableModel.setDataVector(verVectors, vector3);
        }
        return tableModel;
    }

    public void setTableModel(DefaultTableModel tableModel) {
        this.tableModel = tableModel;
    }

    public JScrollPane getScrollPane() {
        if (scrollPane == null) {
            scrollPane = new JScrollPane(getTable());
            scrollPane.setBounds(51, 87, 342, 320);
            scrollPane.setOpaque(false);
            scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            scrollPane.getVerticalScrollBar().setUI(new SrcollPanelUI());
            scrollPane.getVerticalScrollBar().setUnitIncrement(30);
            scrollPane.setBorder(BorderFactory.createEmptyBorder());
            scrollPane.getViewport().setOpaque(false);
            this.add(scrollPane);
        }
        return scrollPane;
    }

    public void setScrollPane(JScrollPane scrollPane) {
        this.scrollPane = scrollPane;
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        this.icon = icon;
    }

    public RichLabel getRichLabPandectMsg() {
        if (richLabPandectMsg == null) {
            richLabPandectMsg = new RichLabel("", UIUtils.TEXT_FONT1);
            richLabPandectMsg.setBounds(404, 91, 204, 70);
            this.add(richLabPandectMsg);
        }
        return richLabPandectMsg;
    }

    public void setRichLabPandectMsg(RichLabel richLabPandectMsg) {
        this.richLabPandectMsg = richLabPandectMsg;
    }

    public RichLabel getRichLabLastMsg() {
        if (richLabLastMsg == null) {
            richLabLastMsg = new RichLabel("", UIUtils.TEXT_FONT1);
            richLabLastMsg.setBounds(404, 181, 204, 70);
            this.add(richLabLastMsg);
        }
        return richLabLastMsg;
    }

    public void setRichLabLastMsg(RichLabel richLabLastMsg) {
        this.richLabLastMsg = richLabLastMsg;
    }

    public RichLabel getRichLabMyMsg() {
        if (richLabMyMsg == null) {
            richLabMyMsg = new RichLabel("", UIUtils.TEXT_FONT1);
            richLabMyMsg.setBounds(404, 273, 204, 154);
            this.add(richLabMyMsg);
        }
        return richLabMyMsg;
    }

    public void setRichLabMyMsg(RichLabel richLabMyMsg) {
        this.richLabMyMsg = richLabMyMsg;
    }

}
